import random

def Merge(a):
        if len(a)>0:
                i=0
                j=0
                mid = len(a)/2
                b=a[:mid]
                c=a[mid:]
                for k in range(len(a)):
                        if i < len(b) and j < len(c):
                                if b[i] < c[j]:
                                        a[k] =b[i]
                                        i+=1
                                else:
                                        a[k]=c[j]
                                        j+=1
                        else:
                                if i < len(b):
                                        a[k]=b[i]
                                        i+=1
                                elif j < len(c):
                                        a[k]=c[j]
                                        j+=1
        return a





def MergeSort(a):
        if len(a)/2 > 0:
                mid = len(a)/2
                a[:mid] = MergeSort(a[:mid])
                a[mid:] = MergeSort(a[mid:])
        return Merge(a)

a=[]
for k in range(10000):
        a.append(random.randrange(1,10000))


f=open("Test.txt",'w')
f.write(str(a))
f.write(str(MergeSort(a)))
f.close()
